using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Pavilion;
using Pavilion.Control;

namespace PavilionGame
{
    public class PauseMenu : Control
    {
        private Panel pauseMenuPanel;
        private Button quitButton, continueButton, animationDesignerButton, drawingToolButton, runTestButton;
        private Label label;

        public event Action QuitPressed, Exit, DrawingToolPressed, AnimationDesignerPressed;

        public PauseMenu(Rectangle bounds)
        {
            AreaBounds = bounds;
            pauseMenuPanel = new Panel(new Rectangle(0, 0, bounds.Width, bounds.Height));
            label = new Label("Pause Menu", new Rectangle(10, 0, 140, 40), new Color(0, 0, 0, 128));
            
            continueButton = new Button("Continue", new Rectangle(25, 100, 175, 40), 0.4f);
            animationDesignerButton = new Button("Animation Designer", new Rectangle(25, 150, 175, 40), 0.4f);
            drawingToolButton = new Button("Drawing Tool", new Rectangle(25, 200, 175, 40), 0.4f);
            runTestButton = new Button("RequestConnection Test", new Rectangle(25, 250, 175, 40), 0.4f);
            quitButton = new Button("Quit", new Rectangle(25, 300, 175, 40), 0.4f);

            pauseMenuPanel.BackgroundColor = new Color(0, 0, 0, 128);
            pauseMenuPanel.Collection.Add(quitButton);
            pauseMenuPanel.Collection.Add(drawingToolButton);
            pauseMenuPanel.Collection.Add(animationDesignerButton);
            pauseMenuPanel.Collection.Add(continueButton);
            pauseMenuPanel.Collection.Add(runTestButton);
            pauseMenuPanel.Collection.Add(label);
            this._Collection.Add(pauseMenuPanel);

            runTestButton.Pressed += new Action(RunTestButton_Pressed);
            quitButton.Pressed += new Action(Quit_ButtonPressed);
            continueButton.Pressed += new Action(ContinueButton_Pressed);
            animationDesignerButton.Pressed += new Action(AnimationDesigner_ButtonPressed);
            drawingToolButton.Pressed += new Action(DrawingToolButton_Pressed);
            this.Input.KeyPressed += new Action<Keys[]>(Keyboard_KeyPressed);
        }

        public override void Dispose()
        {
            runTestButton.Pressed -= new Action(RunTestButton_Pressed);
            quitButton.Pressed -= new Action(Quit_ButtonPressed);
            continueButton.Pressed -= new Action(ContinueButton_Pressed);
            animationDesignerButton.Pressed -= new Action(AnimationDesigner_ButtonPressed);
            drawingToolButton.Pressed -= new Action(DrawingToolButton_Pressed);
            this.Input.KeyPressed -= new Action<Keys[]>(Keyboard_KeyPressed);

            base.Dispose();
        }

        private List<ITest> ObtainTestData()
        {
            List<ITest> testList = new List<ITest>();

            //testList.Add(new ContentBuilder.TestContentBuilder());
            //testList.Add(new Animation.TestAnimation());

            return testList;
        }

        private void OnExit()
        {
            if (Exit != null)
                Exit();
        }

        private void OnAnimationDesignerPressed()
        {
            if (AnimationDesignerPressed != null)
                AnimationDesignerPressed();
        }

        private void OnDrawingToolPressed()
        {
            if (DrawingToolPressed != null)
                DrawingToolPressed();
        }

        private void OnQuitPressed()
        {
            if (QuitPressed != null)
                QuitPressed();
        }

        private void AnimationDesigner_ButtonPressed()
        {
            OnAnimationDesignerPressed();
        }

        private void DrawingToolButton_Pressed()
        {
            OnDrawingToolPressed();
        }

        private void Quit_ButtonPressed()
        {
            OnQuitPressed();
        }

        private void ContinueButton_Pressed()
        {
            OnExit();
        }

        private void RunTestButton_Pressed()
        {
            List<ITest> testList = ObtainTestData();

            foreach (ITest test in testList)
                test.RunTest();

            MessageBox.StaticShowMessage("Test Completed Successfully!");
        }

        private void Keyboard_KeyPressed(Keys[] keys)
        {
            if (keys[0] == Keys.Escape)
                OnExit();
        }
    }
}
